Repository navigation
[patch] Spell NaN and infinity in each target language, with the import it needs - #147
Merged
Merged
Conversation
…rt it needs
A non-finite double literal was written as its round-trip text, so every
target but JavaScript got an undefined name (NaN, Infinity) and C# got the
tokens NaNd and Infinityd. Each generator now spells these as its own
constant: double.NaN / double.PositiveInfinity in C#, std::numeric_limits
in C++, NAN / INFINITY in C, math.NaN() / math.Inf(±1) in Go, f64::NAN /
f64::INFINITY / f64::NEG_INFINITY in Rust, and float("nan") / float("inf")
in Python.
A file holding one now gets the include or import that spelling needs:
<math.h> for C, <limits> for C++, and "math" for Go. It goes through the
existing RequiredImports hook, so an import the file already carries is not
written twice. The reflection walk EnsureConserved used is now the shared
SelfAndDescendants, which is how a generator finds such a literal.
Fixes #78
Fixes #96
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015zULxdhphqscknnLMm1Bk1
|
This was referenced Oct 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #96
Fixes #78
Summary
A non-finite double literal used to be written as its round-trip text. Every target except JavaScript got an undefined name (
NaN,Infinity), and C# got the tokensNaNd/Infinityd. This implements the maintainer's decision from 2026-09-28 (option 1 on #78, with #96's table as the spec): each generator spells these values itself and adds the import its spelling needs.double.NaNdouble.PositiveInfinity/double.NegativeInfinitystd::numeric_limits<double>::quiet_NaN()std::numeric_limits<double>::infinity()(negated)<limits>NANINFINITY/-INFINITY<math.h>math.NaN()math.Inf(1)/math.Inf(-1)"math"f64::NANf64::INFINITY/f64::NEG_INFINITYfloat("nan")float("inf")/float("-inf")NaNInfinity/-InfinityChanges
LanguageGeneratorBaseSpellNonFiniteDouble(double). Its default is the JavaScript spelling.TryGenerateCommonNodesends non-finite doubles to it.EnsureConservedused is now the sharedSelfAndDescendants, andContainsNonFiniteDouble(SourceFile)is built on it.LeadingSignno longer treats NaN as negative. .NET'sdouble.NaNhas its sign bit set.SpellNonFiniteDoubleandRequiredImports. That reuses the existing required-imports mechanism Python already uses forenum, and it already de-duplicates againstSourceFile.Imports.WriteFileDirectives. SoImportGroupsadds"math"the same way it already adds"os"for entry points, and skips it when the file already imports it.Tests
New
Coder.Test/Languages/NonFiniteDoubleLiteralTests.cs:-std=c11 -Wall -Wextra -pedantic), C++ (-std=c++20), Go (go build) and Rust (rustc --crate-type lib). Like the existing compile tests, they report inconclusive when the toolchain is missing.With the fix reverted, 25 of the 34 new test cases fail. The 9 that still pass are the JavaScript spellings, the no-import cases, and the cases where the file already carried the import. The full suite passes: 1052/1052.
🤖 Generated with Claude Code
https://claude.ai/code/session_015zULxdhphqscknnLMm1Bk1
Generated by Claude Code